package com.easyedu.student.service;

import com.easyedu.student.dao.StudentDao;
import com.easyedu.student.dao.StudentSelectDao;
import com.easyedu.student.entity.DO.Student;
import com.easyedu.student.entity.DO.StudentGrade;
import com.easyedu.student.exceptionhandler.MyException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author lmr
 **/
@Service
public class StudentService {
    private final Logger LOGGER = LoggerFactory.getLogger(this.getClass());

    private final StudentDao studentDao;

    private StudentSelectDao studentSelectDao;

    public StudentService(StudentDao studentDao) {
        this.studentDao = studentDao;
    }

    public Student index(Long studentNumber) {
        Student studentInfo = studentDao.getStudentInfoByStudentNumber(studentNumber);
        LOGGER.info("[student] 学生信息：{}" ,studentInfo);
        if (studentInfo == null){
            throw new MyException(1999,"此学生不存在");
        }
        return studentInfo;
    }

    public List<StudentGrade> getStudentGrade(Long studentNumber) {
        List<StudentGrade> studentGrade = studentSelectDao.getStudentGrade(studentNumber);
        if (studentGrade.isEmpty()){
            throw new MyException(1999,"无已出成绩课程");
        }
        return studentGrade;
    }
}
